<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" >
      <el-form-item label="亲属姓名" prop="familyName">
        <el-input
            v-model="queryParams.familyName"
            placeholder="请输入亲属姓名"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="与本人关系" prop="familyRelation">
        <el-input
            v-model="queryParams.familyRelation"
            placeholder="请输入与本人关系"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证件号" prop="famliyCertificatenumber">
        <el-input
            v-model="queryParams.famliyCertificatenumber"
            placeholder="请输入证件号"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证件名称" prop="famliyCertificatename">
        <el-input
            v-model="queryParams.famliyCertificatename"
            placeholder="请输入证件名称"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否与子女共同生活" prop="familyLivetogether" >
        <el-select v-model="queryParams.familyLivetogether" placeholder="请选择是否与子女共同生活" clearable style="width: 200px">
          <el-option
              v-for="dict in sys_yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="婚姻状况" prop="familyMarriage">
        <el-select v-model="queryParams.familyMarriage" placeholder="请选择婚姻状况" clearable style="width: 200px">
          <el-option
              v-for="dict in user_marriage"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="婚姻变化情况" prop="familyMarriagechang">
        <el-select v-model="queryParams.familyMarriagechang" placeholder="请选择婚姻变化情况" clearable style="width: 200px">
          <el-option
              v-for="dict in user_marriage"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="工作" prop="familyOrganization">
        <el-input
            v-model="queryParams.familyOrganization"
            placeholder="请输入工作"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="现任职务" prop="familyJob">
        <el-input
            v-model="queryParams.familyJob"
            placeholder="请输入现任职务"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位性质" prop="famliyJobNature">
        <el-select v-model="queryParams.famliyJobNature" placeholder="请选择单位性质" clearable style="width: 200px">
          <el-option
              v-for="dict in job_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否担任高级职务" prop="famliyIfHighjob">
        <el-select v-model="queryParams.famliyIfHighjob" placeholder="请选择是否担任高级职务" clearable style="width: 200px">
          <el-option
              v-for="dict in sys_yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否在国" prop="famliyIfAbroad">
        <el-select v-model="queryParams.famliyIfAbroad" placeholder="请选择是否在国" clearable style="width: 200px">
          <el-option
              v-for="dict in sys_yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否为单位合伙人或设立人" prop="famliyIfJobPartner">
        <el-select v-model="queryParams.famliyIfJobPartner" placeholder="请选择是否为单位合伙人或设立人" clearable style="width: 200px">
          <el-option
              v-for="dict in sys_yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否在本单位辖区内执业" prop="famliyIfLocal">
        <el-select v-model="queryParams.famliyIfLocal" placeholder="请选择是否在本单位辖区内执业" clearable style="width: 200px">
          <el-option
              v-for="dict in sys_yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="辖区" prop="famliyJurisdiction">
        <el-input
            v-model="queryParams.famliyJurisdiction"
            placeholder="请输入辖区"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="执业范围" prop="famliyBusinessscope">
        <el-input
            v-model="queryParams.famliyBusinessscope"
            placeholder="请输入执业范围"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否提出回避申请" prop="famliyIfAvoid">
        <el-select v-model="queryParams.famliyIfAvoid" placeholder="请选择是否提出回避申请" clearable style="width: 200px">
          <el-option
              v-for="dict in sys_yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="回避申请的具体情形" prop="famliyAvoid">
        <el-input
            v-model="queryParams.famliyAvoid"
            placeholder="请输入回避申请的具体情形"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="Plus"
            @click="handleAdd"
            v-hasPermi="['information:information:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="success"
            plain
            icon="Edit"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['information:information:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="danger"
            plain
            icon="Delete"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['information:information:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExport"
            v-hasPermi="['information:information:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="informationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column label="亲属姓名" align="center" prop="familyName" />
      <el-table-column label="与本人关系" align="center" prop="familyRelation" />
      <el-table-column label="证件号" align="center" prop="famliyCertificatenumber" />
      <el-table-column label="证件名称" align="center" prop="famliyCertificatename" />
      <el-table-column label="是否与子女共同生活" align="center" prop="familyLivetogether">
        <template #default="scope">
          <dict-tag :options="sys_yes_no" :value="scope.row.familyLivetogether"/>
        </template>
      </el-table-column>
      <el-table-column label="婚姻状况" align="center" prop="familyMarriage">
        <template #default="scope">
          <dict-tag :options="user_marriage" :value="scope.row.familyMarriage"/>
        </template>
      </el-table-column>
      <el-table-column label="婚姻变化情况" align="center" prop="familyMarriagechang">
        <template #default="scope">
          <dict-tag :options="user_marriage" :value="scope.row.familyMarriagechang"/>
        </template>
      </el-table-column>
      <el-table-column label="工作" align="center" prop="familyOrganization" />
      <el-table-column label="现任职务" align="center" prop="familyJob" />
      <el-table-column label="单位性质" align="center" prop="famliyJobNature">
        <template #default="scope">
          <dict-tag :options="job_type" :value="scope.row.famliyJobNature"/>
        </template>
      </el-table-column>
      <el-table-column label="是否担任高级职务" align="center" prop="famliyIfHighjob">
        <template #default="scope">
          <dict-tag :options="sys_yes_no" :value="scope.row.famliyIfHighjob"/>
        </template>
      </el-table-column>
      <el-table-column label="是否在国" align="center" prop="famliyIfAbroad">
        <template #default="scope">
          <dict-tag :options="sys_yes_no" :value="scope.row.famliyIfAbroad"/>
        </template>
      </el-table-column>
      <el-table-column label="是否为单位合伙人或设立人" align="center" prop="famliyIfJobPartner">
        <template #default="scope">
          <dict-tag :options="sys_yes_no" :value="scope.row.famliyIfJobPartner"/>
        </template>
      </el-table-column>
      <el-table-column label="是否在本单位辖区内执业" align="center" prop="famliyIfLocal">
        <template #default="scope">
          <dict-tag :options="sys_yes_no" :value="scope.row.famliyIfLocal"/>
        </template>
      </el-table-column>
      <el-table-column label="辖区" align="center" prop="famliyJurisdiction" />
      <el-table-column label="执业范围" align="center" prop="famliyBusinessscope" />
      <el-table-column label="是否提出回避申请" align="center" prop="famliyIfAvoid">
        <template #default="scope">
          <dict-tag :options="sys_yes_no" :value="scope.row.famliyIfAvoid"/>
        </template>
      </el-table-column>
      <el-table-column label="回避申请的具体情形" align="center" prop="famliyAvoid" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['information:information:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['information:information:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />

    <!-- 添加或修改用户家属基础信息对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="informationRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="亲属姓名" prop="familyName">
          <el-input v-model="form.familyName" placeholder="请输入亲属姓名" />
        </el-form-item>
        <el-form-item label="与本人关系" prop="familyRelation">
          <el-input v-model="form.familyRelation" placeholder="请输入与本人关系" />
        </el-form-item>
        <el-form-item label="证件号" prop="famliyCertificatenumber">
          <el-input v-model="form.famliyCertificatenumber" placeholder="请输入证件号" />
        </el-form-item>
        <el-form-item label="证件名称" prop="famliyCertificatename">
          <el-input v-model="form.famliyCertificatename" placeholder="请输入证件名称" />
        </el-form-item>
        <el-form-item label="是否与子女共同生活" prop="familyLivetogether">
          <el-radio-group v-model="form.familyLivetogether">
            <el-radio
                v-for="dict in sys_yes_no"
                :key="dict.value"
                :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="婚姻状况" prop="familyMarriage">
          <el-radio-group v-model="form.familyMarriage">
            <el-radio
                v-for="dict in user_marriage"
                :key="dict.value"
                :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="婚姻变化情况" prop="familyMarriagechang">
          <el-radio-group v-model="form.familyMarriagechang">
            <el-radio
                v-for="dict in user_marriage"
                :key="dict.value"
                :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="工作" prop="familyOrganization">
          <el-input v-model="form.familyOrganization" placeholder="请输入工作" />
        </el-form-item>
        <el-form-item label="现任职务" prop="familyJob">
          <el-input v-model="form.familyJob" placeholder="请输入现任职务" />
        </el-form-item>
        <el-form-item label="单位性质" prop="famliyJobNature">
          <el-radio-group v-model="form.famliyJobNature">
            <el-radio
                v-for="dict in job_type"
                :key="dict.value"
                :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否担任高级职务" prop="famliyIfHighjob">
          <el-radio-group v-model="form.famliyIfHighjob">
            <el-radio
                v-for="dict in sys_yes_no"
                :key="dict.value"
                :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否在国" prop="famliyIfAbroad">
          <el-radio-group v-model="form.famliyIfAbroad">
            <el-radio
                v-for="dict in sys_yes_no"
                :key="dict.value"
                :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否为单位合伙人或设立人" prop="famliyIfJobPartner">
          <el-radio-group v-model="form.famliyIfJobPartner">
            <el-radio
                v-for="dict in sys_yes_no"
                :key="dict.value"
                :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否在本单位辖区内执业" prop="famliyIfLocal">
          <el-radio-group v-model="form.famliyIfLocal">
            <el-radio
                v-for="dict in sys_yes_no"
                :key="dict.value"
                :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="辖区" prop="famliyJurisdiction">
          <el-input v-model="form.famliyJurisdiction" placeholder="请输入辖区" />
        </el-form-item>
        <el-form-item label="执业范围" prop="famliyBusinessscope">
          <el-input v-model="form.famliyBusinessscope" placeholder="请输入执业范围" />
        </el-form-item>
        <el-form-item label="是否提出回避申请" prop="famliyIfAvoid">
          <el-radio-group v-model="form.famliyIfAvoid">
            <el-radio
                v-for="dict in sys_yes_no"
                :key="dict.value"
                :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="回避申请的具体情形" prop="famliyAvoid">
          <el-input v-model="form.famliyAvoid" placeholder="请输入回避申请的具体情形" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Information">
import { listInformation, getInformation, delInformation, addInformation, updateInformation } from "@/api/information/familyBasicInformation.js";

const { proxy } = getCurrentInstance();
const { job_type, sys_yes_no, user_marriage } = proxy.useDict('job_type', 'sys_yes_no', 'user_marriage');

const informationList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    familyName: null,
    familyRelation: null,
    famliyCertificatenumber: null,
    famliyCertificatename: null,
    familyLivetogether: null,
    familyMarriage: null,
    familyMarriagechang: null,
    familyOrganization: null,
    familyJob: null,
    famliyJobNature: null,
    famliyIfHighjob: null,
    famliyIfAbroad: null,
    famliyIfJobPartner: null,
    famliyIfLocal: null,
    famliyJurisdiction: null,
    famliyBusinessscope: null,
    famliyIfAvoid: null,
    famliyAvoid: null
  },
  rules: {
    userId: [
      { required: true, message: "用户编号不能为空", trigger: "blur" }
    ],
    familyName: [
      { required: true, message: "亲属姓名不能为空", trigger: "blur" }
    ],
    familyRelation: [
      { required: true, message: "与本人关系不能为空", trigger: "blur" }
    ],
    famliyCertificatenumber: [
      { required: true, message: "证件号不能为空", trigger: "blur" }
    ],
    famliyCertificatename: [
      { required: true, message: "证件名称不能为空", trigger: "blur" }
    ],
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询用户家属基础信息列表 */
function getList() {
  loading.value = true;
  listInformation(queryParams.value).then(response => {
    informationList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    userId: null,
    familyName: null,
    familyRelation: null,
    famliyCertificatenumber: null,
    famliyCertificatename: null,
    familyLivetogether: null,
    familyMarriage: null,
    familyMarriagechang: null,
    familyOrganization: null,
    familyJob: null,
    famliyJobNature: null,
    famliyIfHighjob: null,
    famliyIfAbroad: null,
    famliyIfJobPartner: null,
    famliyIfLocal: null,
    famliyJurisdiction: null,
    famliyBusinessscope: null,
    famliyIfAvoid: null,
    famliyAvoid: null
  };
  proxy.resetForm("informationRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加用户家属基础信息";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _id = row.id || ids.value
  getInformation(_id).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改用户家属基础信息";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["informationRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateInformation(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addInformation(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除用户家属基础信息编号为"' + _ids + '"的数据项？').then(function () {
    return delInformation(_ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {
  });
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('information/information/export', {
    ...queryParams.value
  }, `information_${new Date().getTime()}.xlsx`)
}

getList();
</script>
